package me.victor.jetpackcompose

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
 * @author song.zheng
 * @create 2024/3/13
 * @description TextFields
 */
@Composable
fun CustomTextField() {
    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        var text by remember { mutableStateOf("") }

        BasicTextField(
            value = text,
            onValueChange = { text = it },
            textStyle = TextStyle(
                color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.Bold
            ),
            singleLine = true,
            cursorBrush = SolidColor(Color.White),
            decorationBox = { innerTextField ->
                Box(
                    modifier = Modifier
                        .height(60.dp)
                        .background(
                            MaterialTheme.colorScheme.primary, shape = MaterialTheme.shapes.small
                        )
                        .border(
                            border = BorderStroke(1.dp, Color.Red),
                            shape = MaterialTheme.shapes.small
                        )
                        .padding(20.dp, 10.dp), contentAlignment = Alignment.CenterStart
                ) {
                    if (text.isEmpty()) {
                        Text(text = "Type here...", color = Color.LightGray)
                    }
                    innerTextField()
                }
            },
//            label = { Text("Title") },
//            leadingIcon = {
//                IconButton(onClick = { }) {
//                    Icon(imageVector = Icons.Default.Email, contentDescription = "Email")
//                }
//            },
//            trailingIcon = {
//                IconButton(onClick = { println("Clicked") }) {
//                    Icon(imageVector = Icons.Default.Check, contentDescription = "Check")
//                }
//            },
            keyboardOptions = KeyboardOptions(
                keyboardType = KeyboardType.Email, imeAction = ImeAction.Search
            ),
            keyboardActions = KeyboardActions(onSearch = { println("Search") })
        )
    }
}